package com.vm.activity;

import com.vm.commons.TabConst.ConValue;
import com.wwt.app.R;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost.TabSpec;

/**
 * 
 * @ProjectName: [WeiMai]
 * @Author: [kent.wang]
 * @CreateDate: [2015年2月4日 下午2:58:07]
 * @Version: [v1.0]
 * 
 */
public class DownloadManageActivity extends TabActivity {

	TabHost tabhost;
	RadioGroup nav_radiogroup;

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.download_manage_navigation);

		tabhost = getTabHost();

		int count = ConValue.downloadTabText.length;
		for (int i = 0; i < count; i++) {
			TabSpec tabSpec1 = tabhost
					.newTabSpec(
							getResources().getString(ConValue.downloadTabText[i]))
					.setIndicator(
							getResources().getString(ConValue.downloadTabText[i]))
					.setContent(getTabItemIntent(i));
			tabhost.addTab(tabSpec1);
		}
		
		initRbtnListener();
		
	}
	
	/**
	 * 初始化导航单选按钮监听
	 */
	public void initRbtnListener() {
		//获取单选按钮group,并设置监听事件
		nav_radiogroup = (RadioGroup)findViewById(R.id.nav_radiogroup);
		nav_radiogroup.setOnCheckedChangeListener(group_listener);
	}
	
	
	/**
	 * 单选按钮监听
	 */
	public OnCheckedChangeListener group_listener = new OnCheckedChangeListener() {

		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			
			switch(checkedId){
			case R.id.btn_downloading:
				tabhost.setCurrentTabByTag(getResources().getString(ConValue.downloadTabText[0]));
				break;
			case R.id.btn_download_complete:
				tabhost.setCurrentTabByTag(getResources().getString(ConValue.downloadTabText[1]));
				break;
			
			}
		}
	};

	private Intent getTabItemIntent(int index) {
		Intent intent = new Intent(this, ConValue.downloadTabClass[index]);
		return intent;
	}

}
